using UnityEngine;
using System.Collections;

public class Timer : MonoBehaviour {
	
	
	public TextMesh timerTarget;
	
	private bool ready;
	private bool canSwitch = true;
	float counter;
	int second;
	int minutes;
	
	IEnumerator Start()
	{
		if(GameObject.FindGameObjectWithTag("Timer"))
		timerTarget = GameObject.FindGameObjectWithTag("Timer").GetComponent<TextMesh>();
		
		else 
			this.enabled =false;
		yield return new WaitForSeconds(0.7f);
		ready = true;
	}
	
	void Update () 
	{
		counter += Time.deltaTime;
	
		if(counter >= 1)
		{
			if(second < 59)
			{
				second ++;
			}
			
			else
			{
				second = 0;
				minutes ++;
			}
			                   
			string timer = string.Format("{0:0},{1:00}",minutes,second);
            string[] split = timer.Split(',');
			
			timerTarget.text = minutes.ToString()+":"+split[1];

			counter = 0;
		}
	}
}
